import random


class Entity:
    def __init__(self, name, hp, atk):
        self.name = name
        self.hp = hp
        self.atk = atk

    def attack(self, entity):
        print(f"{self.name} 对 {entity.name} 发动了攻击")
        entity.hp = entity.hp - self.atk
        print(f"{entity.name} 受到了 {self.atk}")


class Player(Entity):
    def attack(self, entity):
        skill = random.randint(1, 5)

        if skill < 3:
            print(f"{self.name} 对 {entity.name} 发动了攻击")
            entity.hp = entity.hp - self.atk
            print(f"{entity.name} 受到了 {self.atk}")

        else:
            print(f"{self.name} 对 {entity.name} 触发了暴击！")
            entity.hp = entity.hp - self.atk * 2
            print(f"{entity.name} 受到了 {self.atk}")


def main():
    player = Player("玩家", random.randint(30, 50), random.randint(5, 10))

    ghost = Entity("幽灵", random.randint(30, 50), random.randint(6, 12))

    fight(player, ghost)


def fight(entity1, entity2):
    print(
        f"{entity1.name} hp: {entity1.hp} atk: {entity1.atk} 和 {entity2.name} hp: {entity2.hp} atk: {entity2.atk} "
    )

    cont = entity1.hp > 0 and entity2.hp > 0
    while cont:
        entity1.attack(entity2)
        if entity2.hp < 0:
            print(f"{entity2.name} 血量归0，结束战斗")
            break

        entity2.attack(entity1)
        if entity1.hp < 0:
            print(f"{entity1.name} 血量归0，结束战斗")
            break


main()
